<?php

namespace App;

use Eloquent;
use App\Traits\Sortable;

/**
 * App\Depart
 *
 * @property int $id
 * @property string $name 部门名称
 * @property int $company_id 公司id
 * @property int $fid 父级id
 * @property string $sort 迭代
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Depart whereCompanyId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Depart whereFid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Depart whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Depart whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Depart whereSort($value)
 * @mixin \Eloquent
 */
class Depart extends Eloquent
{
    use Sortable;

    public $timestamps = false;

    protected $table = 'depart';

    protected $guarded = [];

    /**
     * @param $company_id
     * @return static
     */
    public static function getDeparts($company_id){
        $departs = Depart::whereCompanyId($company_id)
            ->orderByRaw('Concat(sort,\',\',id) asc')
            ->select(['id','name'])
            ->get();
        $datas = $departs->mapWithKeys(function($item){
            return [$item['id']=>$item['name']];
        });
        return $datas;
    }
}
